package com.snail.test.test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author liwenbo
 * @version 1.0
 * @description: TODO
 * @date 2021/9/14 4:53 下午
 */
public class GameRandom {


    public static void main(String[] args) throws IOException {

        createGroup(2);
    }

    public static void createGroup(int times) throws IOException {
        String wrap = "\r";
        List<String> all = new ArrayList<>(Arrays.asList("涛哥", "赖琛", "特哥", "宇哥", "蜜哥", "大伟哥", "华哥", "群哥", "飞哥", "李文博"));
        List<String> res = new ArrayList<>();
        while (res.size() < 5) {
            String name = all.get(getRandom());
            if (res.contains(name)) {
                continue;
            }
            res.add(name);
        }
        String first = String.join(wrap, res);
        all.removeAll(res);
        String second = String.join(wrap, all);
        File file = new File("/Users/liwenbo/test.txt");
        if(!file.exists()) {
            file.createNewFile();
        }
        Writer writer = new FileWriter(file, true);
        writer.append(String.format("------------------------%d  begin---------------------------", times) + wrap);
        writer.append("-------first group----------" + wrap );
        writer.append(first + wrap);
        writer.append("--------second group---------" + wrap);
        writer.append(second + wrap);
        writer.append(String.format("------------------------%d  end---------------------------", times) + wrap);
        writer.append(wrap).append(wrap);
        writer.flush();
        writer.close();
    }

    public static int getRandom() {
        long l = System.currentTimeMillis();
        int a = (int) (l % 10);
        return a;
    }
}
